package nc.tb.dim;

import java.util.ArrayList;

import nc.tb.dim.data.DimManager;
import nc.tb.dim.data.ViewManager;
import nc.tb.pub.util.NtbLogger;
import nc.vo.pub.BusinessException;

public class SumDef extends DimDef {
	
	private transient static String DIMDEF = "free";
	private transient static String DIMVIEW = "freevalue";

	private transient DimView[] dvs;
	private transient DimDef[] dds;
	
	public DimDef[] getDimDefs() {
		if (dds == null) {
			instance();
		}
		return dds;
	}
	
	public DimView[] getDimViews() {
		if (dvs == null) {
			instance();
		}
		return dvs;
	}
	
	private void instance() {
		ArrayList<DimDef> aldd = new ArrayList<DimDef>();
		ArrayList<DimView> aldv = new ArrayList<DimView>();
		for (int i=1; i<=20; i++) {
			Object pk = getAttributeValue(DIMDEF+i);
			if (pk == null) {
				break;
			}
			try {
				DimDef dd = DimManager.getDimDefByPK((String)pk);
				DimView dv = ViewManager.getDimViewByPK(dd, (String)getAttributeValue(DIMVIEW+i));
				aldd.add(dd);
				aldv.add(dv);
			} 
			catch (BusinessException e) {
				NtbLogger.printException(e);
			}
		}
		dds = aldd.toArray(new DimDef[0]);
		dvs = aldv.toArray(new DimView[0]);
	}
}
